import request from 'lib/request';

// 登录
// loginid: 手机号或身份证
export function signin(mobile, pswd){// 登录
    const body = new FormData();
    body.append('mobile', mobile);
    body.append('pswd', pswd);
    return request.post('rbac/patient/login', { body })
} 

// 注册
// data: { name, gender, birthday, idnumber }
export function signup(data) {
  const body = new FormData();
  Object.keys(data).forEach(key => body.append(key, data[key]));
  return request.post('rbac/patient/regist', { body })
}

// 发送验证码
export function sendSmsCode (mobile){
  let body = {
    mobile,
  }
  return request("rbac/patient/sendSms?"+"mobile="+mobile,{
    method: "GET",
  })
}
// 注册时发送验证码
export function registSmsCode(mobile){
    let body = {
    mobile,
  }
  return request("rbac/patient/registSms?"+"mobile="+mobile,{
    method: "GET",
  })
}

// 验证验证码
export function checkSmsCode (mobile, code, hospitalId){
  let body = {
    mobile,
    code,
  }
  return request("rbac/patient/checkSms?"+"mobile="+mobile+"&code="+code,{
    method: "GET",
  })
}

// 找回密码
// data: { mobile, code, pswd }
export function resetPassword(data) {
  const body = new FormData();
  Object.keys(data).forEach(key => body.append(key, data[key]));
  return request.post('rbac/patient/resetPwd', { body });
}

// 自动登录
export function signauth(){
 const body = new FormData();
  Object.keys(data).forEach(key => body.append(key, data[key]));
  return request.post('rbac/patient/auth', { body }); 
}

